#coding=utf-8
'''
Created on Apr 22, 2016

@author: root
'''
'''
秋霞实现
'''
import re,os
import threading
import time
from time import sleep
import xmlrpclib
import json

class myThread (threading.Thread):  
    def __init__(self, command):
        threading.Thread.__init__(self)
        self.command = command
    def run(self):      
        print "start"   
        os.system(self.command)
        
        
def processPack(count):
    fp=os.popen("ifconfig")
    str1=fp.read()
    file=[]
    c=re.findall(r'((.*)\: )',str1)
    for t in c:
        filename=t[1]+'.txt'
        #print "filename",filename
        file.append(filename)
        command='tshark -i '+t[1]+' -w /home/qiu/'+filename+' -x -T text -a duration:'+count
        myThread(command).start()
        #print command
        #os.system(command
    return file
    
def stringMatch():
    g=os.listdir("/home/qiu")
    str3=''
    for i in g:
        fo=open("/home/qiu/"+i,"r+")
        str2=fo.read()
   # fo=open("json.txt","r+")
    #str=fo.read()
        b=re.findall(r'(\{(.*)\}|]\})',str2,re.M|re.I)
        #b=re.findall(r'(\{(.*)[a-z0-9]{1,})',str2,re.M|re.I)
        for k in b:
           #print "k[0]",k[0]
           str3+=k[0]
           str3+='\n'
    fo.close()
    if str3=='':
        str3='not found json'
    return xmlrpclib.Binary(str3)
if __name__=="__main__":
    #display()
    print processPack("30")
    import time
    sleep(35)
    print stringMatch()
    '''result=display()
    for item in result:
        print item'''
        